package com.czy.owner.ui.order;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;

import com.czy.owner.R;
import com.czy.owner.adapter.GetCommenOrderAdapter;
import com.czy.owner.api.GetCommentOrderApi;
import com.czy.owner.callback.RecycleViewDivider;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.GetCommentModel;
import com.czy.owner.net.http.HttpManager;
import com.czy.owner.net.listener.HttpOnNextListener;
import com.czy.owner.ui.BaseActivity;
import com.czy.owner.utils.MyLog;
import com.czy.owner.utils.PhoneUtils;
import com.easyrecycleview.EasyRecyclerView;
import java.util.List;
import butterknife.BindView;

/**
 * Created by wangyang on 2017/6/14 0014.
 */

public class SeeEvaluateActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener{
    @BindView(R.id.easy_recycleview)
    EasyRecyclerView easyRecycleview;
    private int userOrderId;
    private GetCommenOrderAdapter adapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.common_activity_easyrecycleview;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        getToolbarTitle().setText(R.string.see_evaluate_detail);
        userOrderId = getIntent().getIntExtra("userOrderId", 0);
        easyRecycleview.setLayoutManager(new LinearLayoutManager(SeeEvaluateActivity.this));
        easyRecycleview.addItemDecoration(new RecycleViewDivider(SeeEvaluateActivity.this, LinearLayoutManager.VERTICAL, R.drawable.shape_shopping_strategy_divider_decoration));
        easyRecycleview.setAdapterWithProgress(adapter = new GetCommenOrderAdapter(SeeEvaluateActivity.this));
        easyRecycleview.setRefreshListener(this);
        onRefresh();
    }

    @Override
    protected void updateViews() {

    }

    private void getEvaluateList() {
        GetCommentOrderApi getCommentOrderApi = new GetCommentOrderApi(new HttpOnNextListener<List<GetCommentModel>>() {
            @Override
            public void onNext(List<GetCommentModel> data) {
                adapter.addAll(data);
                if(adapter.getAllData().size()==0){
                    easyRecycleview.setEmptyView(R.layout.view_empty_common);
                    easyRecycleview.showEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                PhoneUtils.ShowToastMessage(SeeEvaluateActivity.this, e.getMessage());
            }
        }, this);
        getCommentOrderApi.setSession(UserHelper.getInstance().getSessionInfoModel(SeeEvaluateActivity.this).getSession());
        getCommentOrderApi.setUserOrderId(userOrderId+"");
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(getCommentOrderApi);

    }

    @Override
    public void onRefresh() {
        adapter.clear();
        getEvaluateList();
    }
}
